package com.itzhanshen.javamail;

import java.util.Arrays;

public class MyTest {
    public static void main(String[] args) {
        int[] num = {1, 2, 3, 4, 5};
        int[] result = twoSum(num, 6);
        System.out.println(Arrays.toString(result));
    }
    // 求两个数之和
    public static int[] twoSum(int[]nums ,int target){
        // 先定义个新的数组,用于存储相对的下标
        int[] arr = new int[2];
        // 循环遍历,获取到结果 存入新数组中
        for (int i = 0; i < nums.length; i++) {
            // 判断亮数相加的结果是否等于target
            for (int j = 0; j < i; j++) {
                if (nums[i] + nums[j] == target) {
                    // 存入新数组中
                    arr[0] = i;
                    arr[1] = j;
                }
            }
        }
        return arr;
    }
}
